<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">   								
	<head> 							
		<title>查询管理</title>	
		
		<%@ include file="../jslib/jquerylib.jsp" %>
		<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
		<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
		<link rel="stylesheet" type="text/css" media="screen" href="<%=request.getContextPath() %>/jslib/js/mypage.js" />
		<link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
	       <!-- 删除结果信息返回 -->
	    	<c:if test="${requestScope.message!=null}">
				<script type="text/javascript">
	  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
	  	 		     window.close();
	  			</script>
	        </c:if>
	 
	<script type="text/javascript">
	$(document).ready(function(){
		var searchname = '<%=request.getParameter("search_en_name")%>'
		
		$("#gridTable").jqGrid({					
			url:'pipePointAction!queryRangeSearch.action?searchname='+searchname,
			datatype: "json",
			height: 300,//ID,JLTYPE_ID,JLTYPE_NAME,REMARKS
			autowidth: true, 
			colNames:['编号','查询字段','查询表','条件字段英文名','条件字段中文名',
			'条件表','条件表主键','查询表外键','所属查询'],
			colModel:[
					{name:'ID',index:'ID', width:60, key:true, sorttype:"int"},								
					{name:'QUERY_FIELD',index:'QUERY_FIELD', width:120},
					{name:'QUERY_TABLE',index:'QUERY_TABLE', width:120},
					{name:'CONDITION_FIELD_EN',index:'CONDITION_FIELD_EN', width:120},
					{name:'CONDITION_FIELD_CN',index:'CONDITION_FIELD_CN', width:120},
					{name:'CONDITION_TABLE',index:'CONDITION_TABLE', width:120},
					{name:'MAIN_FIELD',index:'MAIN_FIELD', width:120},
					{name:'FOREIGN_FIELD',index:'FOREIGN_FIELD', width:120},
					{name:'OWNER',index:'OWNER', width:120},						
			],
			shrinkToFit:false,
			sortname:'id',
			sortorder:'desc',
			viewrecords:true,
			multiselect: true, // 是否显示复选框
			multiboxonly : true, 
			//gridview: true,  //提升速度
			rownumbers: true,//显示行号
			rownumWidth: 30, //行号的宽度
			rowNum:<%=session.getAttribute("SYS_PAGECOUNT")%>,
			rowList:[15,20,50,200,500],
			toolbar: [false,"top"],
			jsonReader: {
				root:"rows",		// 数据行（默认为：rows）
				page: "page",  	// 当前页
				total: "total",  // 总页数
				records: "records",  // 总记录数
				repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
			},
			prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
			pager:"#gridPager",
			caption: "区间查询条件列表"	,
			zIndex:	999							
	});
			
	 jQuery("#gridTable").jqGrid('navGrid','#gridPager',{add:false,edit:false,del:false,search:false,refresh:false});
		jQuery("#gridTable").jqGrid('navButtonAdd','#gridPager',
					{ 	
					caption: "列状态",                          
					title: "Reorder Columns",                           
					onClickButton : function (){                               
					jQuery("#gridTable").jqGrid('setColumns');                           
					}
		}); 
		////doResize(); 										
	}); 
	//查询
	function gridSearch(){
		var searchname = '<%=request.getParameter("search_en_name")%>'
		var params = {  
            "searchname" : encodeURIComponent(searchname),
		};							 
		 var postData = $("#gridTable").jqGrid("getGridParam", "postData");
		 $.extend(postData, params);
		jQuery("#gridTable").jqGrid('setGridParam',
		{
			url:'pipePointAction!queryRangeSearch.action?searchname='+searchname
		}).trigger("reloadGrid", [{page:1}]); 
    } 
	//添加
	function addItem(){
		var searchname = '<%=request.getParameter("search_en_name")%>'	
		$.dialog({
	        title: '添加页面',
	        content: 'url:<%=request.getContextPath() %>/form/auto_search_range_add.jsp?searchname='+searchname,
			okVal: false,//确定按钮文字
	        cancelVal: false,//取消按钮文字
	        min: true, //是否显示最小化按钮
	        max: false,//是否显示最大化按钮
	        fixed: false,//开启静止定位
	        lock: true,//开启锁屏
	        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
	        time: null,//设置对话框显示时间
	        resize: true,//是否允许用户调节尺寸
	        drag: true,//是否允许用户拖动位置
	        cache: false,//是否缓存iframe方式加载的窗口内容页	
	        //width: '800px',    
	        width: '1000px',
	        height: 300,
	        zIndex:	1002,
	        close: function(){
	        	gridSearch();
		    }	        
		});
	}
	function deleteItem(){
		var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
		if (!ids) {
		    alert("请先选择记录!");  
		    return false;  
		}
		/*if(ids.indexOf(",")!=-1){
			alert("只能选择一条记录!");  
		    return false; 
		}*/
		var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
		if(!confirm("是否确认删除？")){
			return false;
		}
		var params = {
					"ids": ids
					};  
		var actionUrl = "pipePointAction!deleteRangeSearch.action";  
		$.ajax({  
			  url : actionUrl,  
		      type : "post", 
		      data : params,  
		      dataType : "json",  
		      cache : false,  
		      error : function(textStatus, errorThrown) {  
		          alert("系统ajax交互错误: " + textStatus.value);  
		      },  
		      success : function(data, textStatus) {
		      	if(data.result=='success'){
		      		alert("删除成功！");       
		      		gridSearch();  
		      	}else{
		      		alert("删除失败！");
		      	}
		    }  
		});
	}
	</script>	
	</head>
	<body>

	<form action="" method="post" ">
		 <table width="100%" border="0" cellpadding="6" cellspacing="0" class="tabman" style="width:100%;margin-bottom:0px">
			<!-- <tr>
				<td>
				&nbsp;&nbsp;查询中文名称：<input type="text" id="form_cn_name" name="form_cn_name" value="" class="input" style="width:150px;"/>&nbsp;&nbsp;
				&nbsp;&nbsp;查询英文名称：<input type="text" id="form_en_name" name="form_en_name" value="" class="input" style="width:150px;"/>&nbsp;&nbsp;
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="button_b" value="查询" onclick="gridSearch()"/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="button_b" value="清空" onclick="reset()"/>
				</td>
			</tr> -->
				</table>		
			<table style="width: 100%;" class="tableCont">
			<tr>
				<td>
					<input id="add" type='button' value='添 加' onclick="addItem();" class='button_b' />
					<input id="update" type='button' value='修 改' onclick='updateItem()' class='button_b' />
					<input id="delete" type='button' value='删 除' onclick='deleteItem();' class='button_b' />
					<input id="search" type='button' value='查 看' onclick='viewItem()' class='button_b' />
				</td>
			</tr>
			<tr>
				<td colspan="4">
					<table id="gridTable"></table>
					<div id="gridPager"></div>
				</td>
			</tr>
		</table>
		</form>
	</body>
</html>
